#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;

namespace USI 
{

	public ref class InfoForm : public System::Windows::Forms::Form
	{
	private:
		bool bUserClose;
		Semaphore ^syncroObject;
	public:
		InfoForm(String ^text, Semaphore ^syncroObject)
		{
			InitializeComponent();
			
			bUserClose = true;
			infoLabel->Text = text;
			this->syncroObject = syncroObject;
		}

		delegate System::Void DoCloseDelegate();

		System::Void DoClose()
		{
			if (this->InvokeRequired)
			{
				this->Invoke(gcnew DoCloseDelegate(this, &InfoForm::DoClose));
				return;
			}

			bUserClose = false;
			Close();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~InfoForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Panel^  panel1;
	private: System::Windows::Forms::Label^  infoLabel;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->panel1 = (gcnew System::Windows::Forms::Panel());
			this->infoLabel = (gcnew System::Windows::Forms::Label());
			this->panel1->SuspendLayout();
			this->SuspendLayout();
			// 
			// panel1
			// 
			this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
			this->panel1->Controls->Add(this->infoLabel);
			this->panel1->Dock = System::Windows::Forms::DockStyle::Fill;
			this->panel1->Location = System::Drawing::Point(0, 0);
			this->panel1->Name = L"panel1";
			this->panel1->Size = System::Drawing::Size(246, 70);
			this->panel1->TabIndex = 0;
			// 
			// infoLabel
			// 
			this->infoLabel->Dock = System::Windows::Forms::DockStyle::Fill;
			this->infoLabel->Font = (gcnew System::Drawing::Font(L"Tahoma", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(204)));
			this->infoLabel->Location = System::Drawing::Point(0, 0);
			this->infoLabel->Name = L"infoLabel";
			this->infoLabel->Size = System::Drawing::Size(244, 68);
			this->infoLabel->TabIndex = 0;
			this->infoLabel->Text = L"Please wait";
			this->infoLabel->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// InfoForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(246, 70);
			this->Controls->Add(this->panel1);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"InfoForm";
			this->ShowIcon = false;
			this->ShowInTaskbar = false;
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"InfoForm";
			this->Shown += gcnew System::EventHandler(this, &InfoForm::InfoForm_Shown);
			this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &InfoForm::InfoForm_FormClosing);
			this->panel1->ResumeLayout(false);
			this->ResumeLayout(false);

		}
#pragma endregion
		private: System::Void InfoForm_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) 
		{
			if (bUserClose)
				e->Cancel = true;
		}
		private: System::Void InfoForm_Shown(System::Object^  sender, System::EventArgs^  e)
		{
			syncroObject->Release();
		}
};
}
